#!/bin/bash
{

	# Created by MichaIng / micha@dietpi.com / dietpi.com

	# Prevent concurrent executions
	(( $(pgrep -cf dietpi-survey_report) > 1 )) && { echo 'Concurrent execution detected. Exiting...'; exit 1; }

	#-----------------------------------------------------------
	# Globals - benchmarks
	#-----------------------------------------------------------
	# NB: PLEASE ENSURE HW_MODEL INDEX ENTRIES MATCH : PREP, dietpi-obtain_hw_model, dietpi-survey_results,
	# NBB: DO NOT REORDER INDEX's. These are now fixed and will never change (due to survey results etc)
	aHW_NAME=()
	aHW_NAME[0]='Raspberry Pi 1 256M'
	aHW_NAME[1]='Raspberry Pi 1/Zero 512M'
	aHW_NAME[2]='Raspberry Pi 2'
	aHW_NAME[3]='Raspberry Pi 3/3+'
	aHW_NAME[4]='Raspberry Pi 4'
	aHW_NAME[10]='Odroid C1'
	aHW_NAME[11]='Odroid XU3/XU4/MC1/HC1/HC2'
	aHW_NAME[12]='Odroid C2'
	aHW_NAME[13]='Odroid U3'
	aHW_NAME[14]='Odroid N1'
	aHW_NAME[15]='Odroid N2'
	aHW_NAME[16]='Odroid C4/HC4'
	aHW_NAME[20]='x86_64 VM'
	aHW_NAME[21]='x86_64 PC'
	aHW_NAME[22]='Generic Device'
	aHW_NAME[30]='OrangePi PC'
	aHW_NAME[31]='OrangePi One'
	aHW_NAME[32]='OrangePi Zero (H2+)'
	aHW_NAME[33]='OrangePi Lite'
	aHW_NAME[34]='OrangePi Plus'
	aHW_NAME[35]='OrangePi Zero Plus 2 (H3/H5)'
	aHW_NAME[36]='OrangePi Win'
	aHW_NAME[37]='OrangePi Prime'
	aHW_NAME[38]='OrangePi PC 2'
	aHW_NAME[39]='LeMaker Guitar'
	aHW_NAME[40]='PINE A64'
	aHW_NAME[41]='OrangePi PC Plus'
	aHW_NAME[42]='ROCKPro64'
	aHW_NAME[43]='ROCK64'
	aHW_NAME[44]='Pinebook'
	aHW_NAME[45]='PINE H64'
	aHW_NAME[50]='BananaPi M2+ (sinovoip)'
	aHW_NAME[51]='BananaPi Pro (Lemaker)'
	aHW_NAME[52]='ASUS Tinker Board'
	aHW_NAME[53]='BananaPi (sinovoip)'
	aHW_NAME[54]='NanoPi K2'
	aHW_NAME[55]='NanoPi R2S'
	aHW_NAME[56]='NanoPi NEO3'
	aHW_NAME[57]='NanoPi NEO Plus2'
	aHW_NAME[58]='NanoPi M4V2'
	aHW_NAME[59]='ZeroPi'
	aHW_NAME[60]='NanoPi NEO'
	aHW_NAME[61]='NanoPi M2/T2'
	aHW_NAME[62]='NanoPi M3/T3/Fire3'
	aHW_NAME[63]='NanoPi M1/T1'
	aHW_NAME[64]='NanoPi NEO Air'
	aHW_NAME[65]='NanoPi NEO2'
	aHW_NAME[66]='NanoPi M1 Plus'
	aHW_NAME[67]='NanoPi K1 Plus'
	aHW_NAME[68]='NanoPi M4/T4/NEO4'
	aHW_NAME[69]='Firefly RK3399'
	aHW_NAME[70]='Sparky SBC'
	aHW_NAME[71]='BeagleBone Black'
	aHW_NAME[72]='ROCK Pi 4'
	aHW_NAME[73]='ROCK Pi S'

	# Core Benchmarks
	aBENCH_CPU_INDEX=()
	aBENCH_RAM_INDEX=()
	aBENCH_ROOTFS_INDEX=()
	# Optional benchmarks
	aBENCH_LAN_INDEX=()
	aBENCH_CUSTOMFS_INDEX=()

	# [$HW_MODEL,${aBENCH_XX_INDEX[$HW_MODEL]}]
	declare -A aBENCH_CPU
	declare -A aBENCH_ROOTFS_WRITE
	declare -A aBENCH_ROOTFS_READ
	declare -A aBENCH_RAM_WRITE
	declare -A aBENCH_RAM_READ
	declare -A aBENCH_CPU_TEMP_START
	declare -A aBENCH_CPU_TEMP_END

	# Optional benchmarks
	declare -A aBENCH_CUSTOMFS_WRITE
	declare -A aBENCH_CUSTOMFS_READ
	declare -A aBENCH_NET_LAN_SPEED

	# Results
	BENCH_RESULTS_CPU_SCALE=2
	aBENCH_RESULT_CPU_MIN=()
	aBENCH_RESULT_CPU_MAX=()
	aBENCH_RESULT_CPU_AVG=()

	aBENCH_RESULT_ROOTFS_WRITE_MIN=()
	aBENCH_RESULT_ROOTFS_WRITE_MAX=()
	aBENCH_RESULT_ROOTFS_WRITE_AVG=()

	aBENCH_RESULT_ROOTFS_READ_MIN=()
	aBENCH_RESULT_ROOTFS_READ_MAX=()
	aBENCH_RESULT_ROOTFS_READ_AVG=()

	aBENCH_RESULT_RAM_WRITE_MIN=()
	aBENCH_RESULT_RAM_WRITE_MAX=()
	aBENCH_RESULT_RAM_WRITE_AVG=()

	aBENCH_RESULT_RAM_READ_MIN=()
	aBENCH_RESULT_RAM_READ_MAX=()
	aBENCH_RESULT_RAM_READ_AVG=()

	aBENCH_RESULT_CPU_TEMP_START_MIN=()
	aBENCH_RESULT_CPU_TEMP_START_MAX=()
	aBENCH_RESULT_CPU_TEMP_START_AVG=()

	aBENCH_RESULT_CPU_TEMP_END_MIN=()
	aBENCH_RESULT_CPU_TEMP_END_MAX=()
	aBENCH_RESULT_CPU_TEMP_END_AVG=()

	aBENCH_RESULT_CUSTOMFS_WRITE_MIN=()
	aBENCH_RESULT_CUSTOMFS_WRITE_MAX=()
	aBENCH_RESULT_CUSTOMFS_WRITE_AVG=()

	aBENCH_RESULT_CUSTOMFS_READ_MIN=()
	aBENCH_RESULT_CUSTOMFS_READ_MAX=()
	aBENCH_RESULT_CUSTOMFS_READ_AVG=()

	aBENCH_RESULT_NET_LAN_SPEED_MIN=()
	aBENCH_RESULT_NET_LAN_SPEED_MAX=()
	aBENCH_RESULT_NET_LAN_SPEED_AVG=()

	#-----------------------------------------------------------
	# Globals - Survey
	#-----------------------------------------------------------
	SURVEY_COUNT_TOTAL=0
	SURVEY_COUNT_EMPTY=0

	declare -A aDIETPI_VERSION
	declare -A aDEVICE_NAME
	declare -A aCPU_ARCH
	aCPU_COUNT=()
	declare -A aDISTRO_VERSION
	declare -A aAUTOSTART_OPTION
	declare -A aSOFTWARE
	aAUTO_SETUP_AUTOMATED=(0 0)
	declare -A aNETWORK_INTERFACE
	# v6.17 addition
	declare -A aGIT_BRANCH
	# v6.31 addition
	aRASPBIAN=(0 0)

	# Convert autostart index to name array
	aAUTOSTART_NAME=()
	aAUTOSTART_NAME[0]='Console manual login'
	aAUTOSTART_NAME[1]='Kodi'
	aAUTOSTART_NAME[2]='Desktop auto login'
	aAUTOSTART_NAME[3]='RetroPie'
	aAUTOSTART_NAME[4]='OpenTyrian'
	aAUTOSTART_NAME[5]='DietPi-Cloudshell'
	aAUTOSTART_NAME[6]='Amiberry fast boot'
	aAUTOSTART_NAME[7]='Console auto login'
	aAUTOSTART_NAME[8]='Amiberry standard boot'
	aAUTOSTART_NAME[9]='DXX-Rebirth'
	aAUTOSTART_NAME[10]='CAVA Spectrum'
	aAUTOSTART_NAME[11]='Chromium'
	aAUTOSTART_NAME[14]='Custom'
	aAUTOSTART_NAME[15]='JRiver'
	# shellcheck disable=SC2034
	aAUTOSTART_NAME[16]='Desktop LightDM login'

	# Convert software index to title array
	aSOFTWARE_NAME=()
	aSOFTWARE_NAME[0]='OpenSSH Client'
	aSOFTWARE_NAME[1]='Samba Client'
	aSOFTWARE_NAME[2]='Folding@Home'
	aSOFTWARE_NAME[3]='MC'
	aSOFTWARE_NAME[4]='ViFM'
	aSOFTWARE_NAME[5]='ALSA'
	aSOFTWARE_NAME[6]='X.Org X server'
	aSOFTWARE_NAME[7]='FFmpeg'
	aSOFTWARE_NAME[8]='Java'
	aSOFTWARE_NAME[9]='Node.js'
	aSOFTWARE_NAME[10]='iftop'
	aSOFTWARE_NAME[11]='IPTraf'
	aSOFTWARE_NAME[12]='Iperf'
	aSOFTWARE_NAME[13]='MTR-Tiny'
	aSOFTWARE_NAME[14]='nLoad'
	aSOFTWARE_NAME[15]='tcpdump'
	aSOFTWARE_NAME[16]='Build-Essentials'
	aSOFTWARE_NAME[17]='Git Client'
	aSOFTWARE_NAME[18]='Emacs'
	aSOFTWARE_NAME[19]='Jed'
	aSOFTWARE_NAME[20]='Vim'
	aSOFTWARE_NAME[21]='Vim-Tiny'
	aSOFTWARE_NAME[22]='QuiteRSS'
	aSOFTWARE_NAME[23]='LXDE'
	aSOFTWARE_NAME[24]='MATE'
	aSOFTWARE_NAME[25]='Xfce'
	aSOFTWARE_NAME[26]='GNUstep'
	aSOFTWARE_NAME[27]='TightVNC Server'
	aSOFTWARE_NAME[28]='TigerVNC Server'
	aSOFTWARE_NAME[29]='XRDP'
	aSOFTWARE_NAME[30]='NoMachine'
	aSOFTWARE_NAME[31]='Kodi'
	aSOFTWARE_NAME[32]='ympd'
	aSOFTWARE_NAME[33]='Airsonic'
	aSOFTWARE_NAME[34]='Subsonic'
	aSOFTWARE_NAME[35]='Logitech Media Server'
	aSOFTWARE_NAME[36]='Squeezelite'
	aSOFTWARE_NAME[37]='Shairport Sync'
	aSOFTWARE_NAME[38]='FreshRSS'
	aSOFTWARE_NAME[39]='ReadyMedia'
	aSOFTWARE_NAME[40]='Ampache'
	aSOFTWARE_NAME[41]='Emby Server'
	aSOFTWARE_NAME[42]='Plex Media Server'
	aSOFTWARE_NAME[43]='Murmur'
	aSOFTWARE_NAME[44]='Transmission'
	aSOFTWARE_NAME[45]='Deluge'
	aSOFTWARE_NAME[46]='qBittorrent'
	aSOFTWARE_NAME[47]='ownCloud'
	aSOFTWARE_NAME[48]='Pydio'
	aSOFTWARE_NAME[49]='Gogs'
	aSOFTWARE_NAME[50]='Syncthing'
	aSOFTWARE_NAME[51]='OpenTyrian'
	aSOFTWARE_NAME[52]='Cuberite'
	aSOFTWARE_NAME[53]='MineOS'
	aSOFTWARE_NAME[54]='phpBB'
	aSOFTWARE_NAME[55]='Wordpress'
	aSOFTWARE_NAME[56]='Single File PHP Gallery'
	aSOFTWARE_NAME[57]='Baïkal'
	aSOFTWARE_NAME[58]='OpenBazaar'
	aSOFTWARE_NAME[59]='RPi Cam Control'
	aSOFTWARE_NAME[60]='WiFi Hotspot'
	aSOFTWARE_NAME[61]='Tor Hotspot'
	aSOFTWARE_NAME[62]='DietPi-CloudShell'
	aSOFTWARE_NAME[63]='LinuxDash'
	aSOFTWARE_NAME[64]='phpSysInfo'
	aSOFTWARE_NAME[65]='Netdata'
	aSOFTWARE_NAME[66]='RPi-Monitor'
	aSOFTWARE_NAME[67]='No-IP'
	aSOFTWARE_NAME[68]='Remot3.it'
	aSOFTWARE_NAME[69]='RPi.GPIO'
	aSOFTWARE_NAME[70]='WiringPi'
	aSOFTWARE_NAME[71]='WebIOPi'
	aSOFTWARE_NAME[72]='I2C'
	aSOFTWARE_NAME[73]='Fail2Ban'
	aSOFTWARE_NAME[74]='InfluxDB'
	aSOFTWARE_NAME[75]='LASP'
	aSOFTWARE_NAME[76]='LAMP'
	aSOFTWARE_NAME[77]='Grafana'
	aSOFTWARE_NAME[78]='LESP'
	aSOFTWARE_NAME[79]='LEMP'
	aSOFTWARE_NAME[80]='Ubooquity'
	aSOFTWARE_NAME[81]='LLSP'
	aSOFTWARE_NAME[82]='LLMP'
	aSOFTWARE_NAME[83]='Apache2'
	aSOFTWARE_NAME[84]='Lighttpd'
	aSOFTWARE_NAME[85]='Nginx'
	aSOFTWARE_NAME[86]='Roon Extension Manager'
	aSOFTWARE_NAME[87]='SQLite'
	aSOFTWARE_NAME[88]='MariaDB'
	aSOFTWARE_NAME[89]='PHP'
	aSOFTWARE_NAME[90]='phpMyAdmin'
	aSOFTWARE_NAME[91]='Redis'
	aSOFTWARE_NAME[92]='Certbot'
	aSOFTWARE_NAME[93]='Pi-hole'
	aSOFTWARE_NAME[94]='ProFTPD'
	aSOFTWARE_NAME[95]='vsftpd'
	aSOFTWARE_NAME[96]='Samba Server'
	aSOFTWARE_NAME[97]='OpenVPN'
	aSOFTWARE_NAME[98]='HAProxy'
	aSOFTWARE_NAME[99]='EmonPi'
	aSOFTWARE_NAME[100]='PiJuice'
	aSOFTWARE_NAME[101]='Logrotate'
	aSOFTWARE_NAME[102]='Rsyslog'
	aSOFTWARE_NAME[103]='DietPi-RAMlog'
	aSOFTWARE_NAME[104]='Dropbear'
	aSOFTWARE_NAME[105]='OpenSSH Server'
	aSOFTWARE_NAME[106]='Lidarr'
	aSOFTWARE_NAME[107]='rTorrent'
	aSOFTWARE_NAME[108]='Amiberry'
	aSOFTWARE_NAME[109]='NFS Server'
	aSOFTWARE_NAME[110]='NFS Client'
	aSOFTWARE_NAME[111]='UrBackup Server'
	aSOFTWARE_NAME[112]='DXX-Rebirth'
	aSOFTWARE_NAME[113]='Chromium'
	aSOFTWARE_NAME[114]='Nextcloud'
	aSOFTWARE_NAME[115]='Webmin'
	aSOFTWARE_NAME[116]='SickRage'
	aSOFTWARE_NAME[117]='PiVPN'
	aSOFTWARE_NAME[118]='Mopidy'
	aSOFTWARE_NAME[119]='CAVA'
	aSOFTWARE_NAME[120]='RealVNC Server'
	aSOFTWARE_NAME[121]='Roon Bridge'
	aSOFTWARE_NAME[122]='Node-RED'
	aSOFTWARE_NAME[123]='Mosquitto '
	aSOFTWARE_NAME[124]='NAA daemon'
	aSOFTWARE_NAME[125]='Tomcat8'
	aSOFTWARE_NAME[126]='LibSSL1.0.0'
	aSOFTWARE_NAME[127]='NeoVim'
	aSOFTWARE_NAME[128]='MPD'
	aSOFTWARE_NAME[129]='O!MPD'
	aSOFTWARE_NAME[130]='Python Pip'
	aSOFTWARE_NAME[131]='Blynk Server'
	aSOFTWARE_NAME[132]='Aria2'
	aSOFTWARE_NAME[133]='YaCy'
	aSOFTWARE_NAME[134]='Tonido'
	aSOFTWARE_NAME[135]='IceCast'
	aSOFTWARE_NAME[136]='MotionEye'
	aSOFTWARE_NAME[137]='CloudPrint'
	aSOFTWARE_NAME[138]='VirtualHere'
	aSOFTWARE_NAME[139]='SABnzbd'
	aSOFTWARE_NAME[140]='SDL2'
	aSOFTWARE_NAME[141]='Spotify Connect Web'
	aSOFTWARE_NAME[142]='CouchPotato'
	aSOFTWARE_NAME[143]='Koel'
	aSOFTWARE_NAME[144]='Sonarr'
	aSOFTWARE_NAME[145]='Radarr'
	aSOFTWARE_NAME[146]='Tautulli'
	aSOFTWARE_NAME[147]='Jackett'
	#aSOFTWARE_NAME[148]=
	aSOFTWARE_NAME[149]='NZBGet'
	aSOFTWARE_NAME[150]='Mono'
	aSOFTWARE_NAME[151]='Nvidia'
	aSOFTWARE_NAME[152]='Avahi-Daemon'
	aSOFTWARE_NAME[153]='OctoPrint'
	aSOFTWARE_NAME[154]='Roon Server'
	aSOFTWARE_NAME[155]='HTPC Manager'
	aSOFTWARE_NAME[156]='Steam'
	aSOFTWARE_NAME[157]='Home Assistant'
	aSOFTWARE_NAME[158]='MinIO'
	aSOFTWARE_NAME[159]='Allo'
	aSOFTWARE_NAME[160]='Allo_update'
	aSOFTWARE_NAME[161]='FuguHub'
	aSOFTWARE_NAME[162]='Docker'
	aSOFTWARE_NAME[163]='GMediaRender'
	aSOFTWARE_NAME[164]='Nukkit'
	aSOFTWARE_NAME[165]='Gitea'
	aSOFTWARE_NAME[166]='PI-SPC'
	aSOFTWARE_NAME[167]='Raspotify'
	#aSOFTWARE_NAME[168]=
	aSOFTWARE_NAME[169]='Google AIY'

	# v6.14 (earliest version that can currently upload) + v6.15
	aSOFTWARE_NAME6_14=()
	aSOFTWARE_NAME6_15=()
	for i in "${!aSOFTWARE_NAME[@]}"
	do
		aSOFTWARE_NAME6_14[$i]=${aSOFTWARE_NAME[$i]}
		aSOFTWARE_NAME6_15[$i]=${aSOFTWARE_NAME6_14[$i]}
	done
	aSOFTWARE_NAME6_15[148]='myMPD'

	# v6.16 + v6.17 + v6.18
	aSOFTWARE_NAME6_16=()
	aSOFTWARE_NAME6_17=()
	aSOFTWARE_NAME6_18=()
	for i in "${!aSOFTWARE_NAME6_15[@]}"
	do
		aSOFTWARE_NAME6_16[$i]=${aSOFTWARE_NAME6_15[$i]}
		aSOFTWARE_NAME6_17[$i]=${aSOFTWARE_NAME6_16[$i]}
		aSOFTWARE_NAME6_18[$i]=${aSOFTWARE_NAME6_17[$i]}
	done
	aSOFTWARE_NAME6_18[168]='Nextcloud Talk'

	# v6.19 + v6.20
	aSOFTWARE_NAME6_19=()
	aSOFTWARE_NAME6_20=()
	for i in "${!aSOFTWARE_NAME6_18[@]}"
	do
		aSOFTWARE_NAME6_19[$i]=${aSOFTWARE_NAME6_18[$i]}
		aSOFTWARE_NAME6_20[$i]=${aSOFTWARE_NAME6_19[$i]}
	done
	aSOFTWARE_NAME6_20[116]='Medusa'
	aSOFTWARE_NAME6_20[170]='UnRAR'
	aSOFTWARE_NAME6_20[171]='DietPi-NordVPN'
	aSOFTWARE_NAME6_20[172]='WireGuard'

	# v6.21 + v6.22 + v6.23
	aSOFTWARE_NAME6_21=()
	aSOFTWARE_NAME6_22=()
	aSOFTWARE_NAME6_23=()
	for i in "${!aSOFTWARE_NAME6_20[@]}"
	do
		aSOFTWARE_NAME6_21[$i]=${aSOFTWARE_NAME6_20[$i]}
		aSOFTWARE_NAME6_22[$i]=${aSOFTWARE_NAME6_21[$i]}
		aSOFTWARE_NAME6_23[$i]=${aSOFTWARE_NAME6_22[$i]}
	done
	aSOFTWARE_NAME6_23[173]='LXQt'
	aSOFTWARE_NAME6_23[174]='GIMP'
	aSOFTWARE_NAME6_23[175]='Xfce Power Manager'

	# v6.24 + v6.25
	aSOFTWARE_NAME6_24=()
	aSOFTWARE_NAME6_25=()
	for i in "${!aSOFTWARE_NAME6_23[@]}"
	do
		aSOFTWARE_NAME6_24[$i]=${aSOFTWARE_NAME6_23[$i]}
		aSOFTWARE_NAME6_25[$i]=${aSOFTWARE_NAME6_24[$i]}
	done
	aSOFTWARE_NAME6_25[176]='Mycroft AI'

	# v6.26
	aSOFTWARE_NAME6_26=()
	for i in "${!aSOFTWARE_NAME6_25[@]}"
	do
		aSOFTWARE_NAME6_26[$i]=${aSOFTWARE_NAME6_25[$i]}
	done
	unset -v 'aSOFTWARE_NAME6_26[27]' # TightVNC: Replaced by TigerVNC on Stretch+
	unset -v 'aSOFTWARE_NAME6_26[140]' # SDL2: Merged into Amiberry for targeted minimal install


	# v6.27
	aSOFTWARE_NAME6_27=()
	for i in "${!aSOFTWARE_NAME6_26[@]}"
	do
		aSOFTWARE_NAME6_27[$i]=${aSOFTWARE_NAME6_26[$i]}
	done
	aSOFTWARE_NAME6_27[27]='TasmoAdmin'

	# v6.28 + v6.29
	aSOFTWARE_NAME6_28=()
	aSOFTWARE_NAME6_29=()
	for i in "${!aSOFTWARE_NAME6_27[@]}"
	do
		aSOFTWARE_NAME6_28[$i]=${aSOFTWARE_NAME6_27[$i]}
		aSOFTWARE_NAME6_29[$i]=${aSOFTWARE_NAME6_28[$i]}
	done
	aSOFTWARE_NAME6_29[140]='Domoticz'

	# v6.30 + v6.31
	aSOFTWARE_NAME6_30=()
	aSOFTWARE_NAME6_31=()
	for i in "${!aSOFTWARE_NAME6_29[@]}"
	do
		aSOFTWARE_NAME6_30[$i]=${aSOFTWARE_NAME6_29[$i]}
		aSOFTWARE_NAME6_31[$i]=${aSOFTWARE_NAME6_30[$i]}
	done
	aSOFTWARE_NAME6_31[177]='Firefox Sync Server'

	# v6.32
	aSOFTWARE_NAME6_32=()
	for i in "${!aSOFTWARE_NAME6_31[@]}"
	do
		aSOFTWARE_NAME6_32[$i]=${aSOFTWARE_NAME6_31[$i]}
	done
	aSOFTWARE_NAME6_32[178]='Jellyfin'
	aSOFTWARE_NAME6_32[179]='Komga'

	# v6.33
	aSOFTWARE_NAME6_33=()
	for i in "${!aSOFTWARE_NAME6_32[@]}"
	do
		aSOFTWARE_NAME6_33[$i]=${aSOFTWARE_NAME6_32[$i]}
	done
	aSOFTWARE_NAME6_33[180]='Bazarr'

	# v6.34
	aSOFTWARE_NAME6_34=()
	for i in "${!aSOFTWARE_NAME6_33[@]}"
	do
		aSOFTWARE_NAME6_34[$i]=${aSOFTWARE_NAME6_33[$i]}
	done
	unset -v 'aSOFTWARE_NAME6_34[62]' # DietPi-CloudShell
	unset -v 'aSOFTWARE_NAME6_34[134]' # Tonido
	unset -v 'aSOFTWARE_NAME6_34[137]' # CloudPrint
	aSOFTWARE_NAME6_34[181]='PaperMC'
	aSOFTWARE_NAME6_34[182]='Unbound'
	aSOFTWARE_NAME6_34[183]='Bitwarden_RS'
	aSOFTWARE_NAME6_34[184]='Tor Relay'
	aSOFTWARE_NAME6_34[185]='Portainer'

	# v6.35
	aSOFTWARE_NAME6_35=()
	for i in "${!aSOFTWARE_NAME6_34[@]}"
	do
		aSOFTWARE_NAME6_35[$i]=${aSOFTWARE_NAME6_34[$i]}
	done
	aSOFTWARE_NAME6_35[62]='Box86'
	aSOFTWARE_NAME6_35[134]='Docker Compose'
	aSOFTWARE_NAME6_35[137]='mjpg-streamer'

	# v7.0 (identical to v6.35 transition version)
	aSOFTWARE_NAME7_0=()
	for i in "${!aSOFTWARE_NAME6_35[@]}"
	do
		# shellcheck disable=SC2034
		aSOFTWARE_NAME7_0[$i]=${aSOFTWARE_NAME6_35[$i]}
	done

	Main(){

		# Copy files to RAM to speed up sourcing
		#mkdir -p /tmp/dietpi-survey_report
		#cp /home/dietpi-survey/survey/*.txt /tmp/dietpi-survey_report/ # cp: Argument list too long
		rm -Rf /tmp/dietpi-survey_report || exit 1
		cp -R /home/dietpi-survey/survey /tmp/dietpi-survey_report || exit 1

		cd /tmp/dietpi-survey_report || exit 1
		for file in *.txt
		do

			# Filled and empty survey files
			((SURVEY_COUNT_TOTAL++))
			if [[ ! -s $file ]]; then

				((SURVEY_COUNT_EMPTY++))
				continue

			fi

			# Source survey files
			[[ $(<"$file") == '#!/bin/bash'* ]] || continue

			. "$file"

			# Add bench to array
			[[ $BENCH_HW_MODEL =~ ^[0-9]+$ ]] || continue

			# CPU
			# - BENCH_CPU: Remove decimal point, equals times 100 since CPU time is always in x.xx
			BENCH_CPU=${BENCH_CPU/.}
			if [[ $BENCH_CPU =~ ^[0-9]*[1-9][0-9]*$ && $BENCH_CPU_TEMP_START =~ ^[0-9]+$ && $BENCH_CPU_TEMP_END =~ ^[0-9]+$ ]]; then

				aBENCH_CPU[$BENCH_HW_MODEL,${aBENCH_CPU_INDEX[$BENCH_HW_MODEL]:=0}]=$BENCH_CPU

				# Patch for 5 digit CPU temps: https://github.com/MichaIng/DietPi/issues/2715
				(( $BENCH_CPU_TEMP_START > 200 )) && (( BENCH_CPU_TEMP_START /= 1000 ))
				(( $BENCH_CPU_TEMP_END > 200 )) && (( BENCH_CPU_TEMP_END /= 1000 ))

				aBENCH_CPU_TEMP_START[$BENCH_HW_MODEL,${aBENCH_CPU_INDEX[$BENCH_HW_MODEL]}]=$BENCH_CPU_TEMP_START
				aBENCH_CPU_TEMP_END[$BENCH_HW_MODEL,${aBENCH_CPU_INDEX[$BENCH_HW_MODEL]}]=$BENCH_CPU_TEMP_END
				((aBENCH_CPU_INDEX[$BENCH_HW_MODEL]++))

			fi

			# RootFS
			# - Remove decimal places
			BENCH_ROOTFS_WRITE=${BENCH_ROOTFS_WRITE%%.*}
			BENCH_ROOTFS_READ=${BENCH_ROOTFS_READ%%.*}
			if [[ $BENCH_ROOTFS_WRITE =~ ^[0-9]*[1-9][0-9]*$ && $BENCH_ROOTFS_READ =~ ^[0-9]*[1-9][0-9]*$ ]]; then

				aBENCH_ROOTFS_WRITE[$BENCH_HW_MODEL,${aBENCH_ROOTFS_INDEX[$BENCH_HW_MODEL]:=0}]=$BENCH_ROOTFS_WRITE
				aBENCH_ROOTFS_READ[$BENCH_HW_MODEL,${aBENCH_ROOTFS_INDEX[$BENCH_HW_MODEL]}]=$BENCH_ROOTFS_READ
				((aBENCH_ROOTFS_INDEX[$BENCH_HW_MODEL]++))

			fi

			# RAM
			# - https://github.com/MichaIng/DietPi/issues/2715 | nullify this score and ignore it in min/max/avg processing.
			# - Remove decimal places
			BENCH_RAM_WRITE=${BENCH_RAM_WRITE%%.*}
			BENCH_RAM_READ=${BENCH_RAM_READ%%.*}
			if [[ $BENCH_VERSION =~ ^[0-9]+$ && $BENCH_RAM_WRITE =~ ^[0-9]*[1-9][0-9]*$ && $BENCH_RAM_READ =~ ^[0-9]*[1-9][0-9]*$ ]] && (( $BENCH_VERSION > 1 )); then

				aBENCH_RAM_WRITE[$BENCH_HW_MODEL,${aBENCH_RAM_INDEX[$BENCH_HW_MODEL]:=0}]=$BENCH_RAM_WRITE
				aBENCH_RAM_READ[$BENCH_HW_MODEL,${aBENCH_RAM_INDEX[$BENCH_HW_MODEL]}]=$BENCH_RAM_READ
				((aBENCH_RAM_INDEX[$BENCH_HW_MODEL]++))

			fi

			# Custom FS
			# - Remove decimal places
			BENCH_CUSTOMFS_WRITE=${BENCH_CUSTOMFS_WRITE%%.*}
			BENCH_CUSTOMFS_READ=${BENCH_CUSTOMFS_READ%%.*}
			if [[ $BENCH_CUSTOMFS_WRITE =~ ^[0-9]*[1-9][0-9]*$ && $BENCH_CUSTOMFS_READ =~ ^[0-9]*[1-9][0-9]*$ ]]; then

				aBENCH_CUSTOMFS_WRITE[$BENCH_HW_MODEL,${aBENCH_CUSTOMFS_INDEX[$BENCH_HW_MODEL]:=0}]=$BENCH_CUSTOMFS_WRITE
				aBENCH_CUSTOMFS_READ[$BENCH_HW_MODEL,${aBENCH_CUSTOMFS_INDEX[$BENCH_HW_MODEL]}]=$BENCH_CUSTOMFS_READ
				((aBENCH_CUSTOMFS_INDEX[$BENCH_HW_MODEL]++))

			fi

			# LAN
			# - Remove decimal places
			BENCH_NET_LAN_SPEED=${BENCH_NET_LAN_SPEED%%.*}
			if [[ $BENCH_NET_LAN_SPEED =~ ^[0-9]*[1-9][0-9]*$ ]]; then

				aBENCH_NET_LAN_SPEED[$BENCH_HW_MODEL,${aBENCH_LAN_INDEX[$BENCH_HW_MODEL]:=0}]=$BENCH_NET_LAN_SPEED
				((aBENCH_LAN_INDEX[$BENCH_HW_MODEL]++))

			fi

			# Done, clear vars
			unset -v BENCH_VERSION BENCH_HW_MODEL
			unset -v BENCH_CPU BENCH_CPU_TEMP_START BENCH_CPU_TEMP_END
			unset -v BENCH_ROOTFS_WRITE BENCH_ROOTFS_READ
			unset -v BENCH_RAM_WRITE BENCH_RAM_READ
			unset -v BENCH_CUSTOMFS_WRITE BENCH_CUSTOMFS_READ
			unset -v BENCH_NET_LAN_SPEED

		done

		# Navigate to parent /tmp
		cd /tmp || exit 1

		# Clean up reports dir
		rm -R /tmp/dietpi-survey_report || exit 1

		# Optin count
		SURVEY_COUNT_OPTIN=$(( $SURVEY_COUNT_TOTAL - $SURVEY_COUNT_EMPTY ))

		# Merge old and new hardware model names
		for i in "${!aDEVICE_NAME[@]}"
		do

			[[ $i == 'RPi B (ECN0001) (armv6l)' ]] && ((aDEVICE_NAME['RPi B (armv6l)']+=aDEVICE_NAME["$i"])) && unset "aDEVICE_NAME[$i]"
			[[ $i == 'RPi  (armv6l)' ]] && ((aDEVICE_NAME['RPi (Unknown) (armv6l)']+=aDEVICE_NAME["$i"])) && unset "aDEVICE_NAME[$i]"
			[[ $i == 'RPi  (armv7l)' ]] && ((aDEVICE_NAME['RPi (Unknown) (armv7l)']+=aDEVICE_NAME["$i"])) && unset "aDEVICE_NAME[$i]"
			[[ $i == 'Odroid XU3/XU4/HC1/HC2 (armv7l)' ]] && ((aDEVICE_NAME['Odroid XU3/XU4/MC1/HC1/HC2 (armv7l)']+=aDEVICE_NAME["$i"])) && unset "aDEVICE_NAME[$i]"
			[[ $i == 'Odroid C4 (aarch64)' ]] && ((aDEVICE_NAME['Odroid C4/HC4 (aarch64)']+=aDEVICE_NAME["$i"])) && unset "aDEVICE_NAME[$i]" # v6.35
			[[ $i == 'Asus Tinker Board (armv7l)' ]] && ((aDEVICE_NAME['ASUS Tinker Board (armv7l)']+=aDEVICE_NAME["$i"])) && unset "aDEVICE_NAME[$i]"
			[[ $i == 'Pine A64 (aarch64)' ]] && ((aDEVICE_NAME['PINE A64 (aarch64)']+=aDEVICE_NAME["$i"])) && unset "aDEVICE_NAME[$i]"
			[[ $i == 'Pine H64 (aarch64)' ]] && ((aDEVICE_NAME['PINE H64 (aarch64)']+=aDEVICE_NAME["$i"])) && unset "aDEVICE_NAME[$i]"
			[[ $i == 'Rock64 (aarch64)' ]] && ((aDEVICE_NAME['ROCK64 (aarch64)']+=aDEVICE_NAME["$i"])) && unset "aDEVICE_NAME[$i]"
			[[ $i == 'RockPro64 (aarch64)' ]] && ((aDEVICE_NAME['ROCKPro64 (aarch64)']+=aDEVICE_NAME["$i"])) && unset "aDEVICE_NAME[$i]"
			[[ $i == 'Pinebook A64 (aarch64)' ]] && ((aDEVICE_NAME['Pinebook (aarch64)']+=aDEVICE_NAME["$i"])) && unset "aDEVICE_NAME[$i]"
			[[ $i == 'Pinebook 1080p (aarch64)' ]] && ((aDEVICE_NAME['Pinebook (aarch64)']+=aDEVICE_NAME["$i"])) && unset "aDEVICE_NAME[$i]"
			[[ $i == 'NanoPi Neo (armv7l)' ]] && ((aDEVICE_NAME['NanoPi NEO (armv7l)']+=aDEVICE_NAME["$i"])) && unset "aDEVICE_NAME[$i]"
			[[ $i == 'NanoPi NEO 2 (aarch64)' ]] && ((aDEVICE_NAME['NanoPi NEO2 (aarch64)']+=aDEVICE_NAME["$i"])) && unset "aDEVICE_NAME[$i]"
			[[ $i == 'NanoPi M3/T3/F3 (aarch64)' ]] && ((aDEVICE_NAME['NanoPi M3/T3/Fire3 (aarch64)']+=aDEVICE_NAME["$i"])) && unset "aDEVICE_NAME[$i]"
			[[ $i == 'NanoPi M3/T3/F3 (armv7l)' ]] && ((aDEVICE_NAME['NanoPi M3/T3/Fire3 (armv7l)']+=aDEVICE_NAME["$i"])) && unset "aDEVICE_NAME[$i]"
			[[ $i == 'BBB (armv7l)' ]] && ((aDEVICE_NAME['BeagleBone Black (armv7l)']+=aDEVICE_NAME["$i"])) && unset "aDEVICE_NAME[$i]"
			[[ $i == 'Unknown Device (armv7l)' ]] && ((aDEVICE_NAME['Generic Device (armv7l)']+=aDEVICE_NAME["$i"])) && unset "aDEVICE_NAME[$i]"
			[[ $i == 'Unknown Device (aarch64)' ]] && ((aDEVICE_NAME['Generic Device (aarch64)']+=aDEVICE_NAME["$i"])) && unset "aDEVICE_NAME[$i]"

		done

		# Process all results, for later use in HTML printout
		# - NB: HW_MODEL array based

		# CPU
		for i in "${!aBENCH_CPU_INDEX[@]}"
		do

			aBENCH_RESULT_CPU_MIN[$i]=
			aBENCH_RESULT_CPU_MAX[$i]=
			aBENCH_RESULT_CPU_AVG[$i]=
			aBENCH_RESULT_CPU_TEMP_START_MIN[$i]=
			aBENCH_RESULT_CPU_TEMP_START_MAX[$i]=
			aBENCH_RESULT_CPU_TEMP_START_AVG[$i]=
			aBENCH_RESULT_CPU_TEMP_END_MIN[$i]=
			aBENCH_RESULT_CPU_TEMP_END_MAX[$i]=
			aBENCH_RESULT_CPU_TEMP_END_AVG[$i]=

			for (( j=0; j<${aBENCH_CPU_INDEX[$i]}; j++ ))
			do

				(( ${aBENCH_CPU[$i,$j]} < ${aBENCH_RESULT_CPU_MIN[$i]:=${aBENCH_CPU[$i,$j]}} )) && aBENCH_RESULT_CPU_MIN[$i]=${aBENCH_CPU[$i,$j]}
				(( ${aBENCH_CPU[$i,$j]} > ${aBENCH_RESULT_CPU_MAX[$i]:=${aBENCH_CPU[$i,$j]}} )) && aBENCH_RESULT_CPU_MAX[$i]=${aBENCH_CPU[$i,$j]}
				(( aBENCH_RESULT_CPU_AVG[$i] += ${aBENCH_CPU[$i,$j]} ))

				(( ${aBENCH_CPU_TEMP_START[$i,$j]} < ${aBENCH_RESULT_CPU_TEMP_START_MIN[$i]:=${aBENCH_CPU_TEMP_START[$i,$j]}} )) && aBENCH_RESULT_CPU_TEMP_START_MIN[$i]=${aBENCH_CPU_TEMP_START[$i,$j]}
				(( ${aBENCH_CPU_TEMP_START[$i,$j]} > ${aBENCH_RESULT_CPU_TEMP_START_MAX[$i]:=${aBENCH_CPU_TEMP_START[$i,$j]}} )) && aBENCH_RESULT_CPU_TEMP_START_MAX[$i]=${aBENCH_CPU_TEMP_START[$i,$j]}
				(( aBENCH_RESULT_CPU_TEMP_START_AVG[$i] += ${aBENCH_CPU_TEMP_START[$i,$j]} ))

				(( ${aBENCH_CPU_TEMP_END[$i,$j]} < ${aBENCH_RESULT_CPU_TEMP_END_MIN[$i]:=${aBENCH_CPU_TEMP_END[$i,$j]}} )) && aBENCH_RESULT_CPU_TEMP_END_MIN[$i]=${aBENCH_CPU_TEMP_END[$i,$j]}
				(( ${aBENCH_CPU_TEMP_END[$i,$j]} > ${aBENCH_RESULT_CPU_TEMP_END_MAX[$i]:=${aBENCH_CPU_TEMP_END[$i,$j]}} )) && aBENCH_RESULT_CPU_TEMP_END_MAX[$i]=${aBENCH_CPU_TEMP_END[$i,$j]}
				(( aBENCH_RESULT_CPU_TEMP_END_AVG[$i] += ${aBENCH_CPU_TEMP_END[$i,$j]} ))

				# Last item in current array. Work out averages
				(( $j == ${aBENCH_CPU_INDEX[$i]} - 1 )) || continue
				# - Devide CPU times by 100 and scale to revert decimal point removal
				aBENCH_RESULT_CPU_MIN[$i]=$(printf "%.${BENCH_RESULTS_CPU_SCALE}f" "${aBENCH_RESULT_CPU_MIN[$i]}e-2")
				aBENCH_RESULT_CPU_MAX[$i]=$(printf "%.${BENCH_RESULTS_CPU_SCALE}f" "${aBENCH_RESULT_CPU_MAX[$i]}e-2")
				aBENCH_RESULT_CPU_AVG[$i]=$(printf "%.${BENCH_RESULTS_CPU_SCALE}f" "$((${aBENCH_RESULT_CPU_AVG[$i]}*10/${aBENCH_CPU_INDEX[$i]}+1))e-3")
				aBENCH_RESULT_CPU_TEMP_START_AVG[$i]=$(( ${aBENCH_RESULT_CPU_TEMP_START_AVG[$i]} / ${aBENCH_CPU_INDEX[$i]} ))
				aBENCH_RESULT_CPU_TEMP_END_AVG[$i]=$(( ${aBENCH_RESULT_CPU_TEMP_END_AVG[$i]} / ${aBENCH_CPU_INDEX[$i]} ))

			done

		done

		# RootFS
		for i in "${!aBENCH_ROOTFS_INDEX[@]}"
		do

			aBENCH_RESULT_ROOTFS_WRITE_MIN[$i]=
			aBENCH_RESULT_ROOTFS_WRITE_MAX[$i]=
			aBENCH_RESULT_ROOTFS_WRITE_AVG[$i]=
			aBENCH_RESULT_ROOTFS_READ_MIN[$i]=
			aBENCH_RESULT_ROOTFS_READ_MAX[$i]=
			aBENCH_RESULT_ROOTFS_READ_AVG[$i]=

			for (( j=0; j<${aBENCH_ROOTFS_INDEX[$i]}; j++ ))
			do

				(( ${aBENCH_ROOTFS_WRITE[$i,$j]} < ${aBENCH_RESULT_ROOTFS_WRITE_MIN[$i]:=${aBENCH_ROOTFS_WRITE[$i,$j]}} )) && aBENCH_RESULT_ROOTFS_WRITE_MIN[$i]=${aBENCH_ROOTFS_WRITE[$i,$j]}
				(( ${aBENCH_ROOTFS_WRITE[$i,$j]} > ${aBENCH_RESULT_ROOTFS_WRITE_MAX[$i]:=${aBENCH_ROOTFS_WRITE[$i,$j]}} )) && aBENCH_RESULT_ROOTFS_WRITE_MAX[$i]=${aBENCH_ROOTFS_WRITE[$i,$j]}
				(( aBENCH_RESULT_ROOTFS_WRITE_AVG[$i] += ${aBENCH_ROOTFS_WRITE[$i,$j]} ))

				(( ${aBENCH_ROOTFS_READ[$i,$j]} < ${aBENCH_RESULT_ROOTFS_READ_MIN[$i]:=${aBENCH_ROOTFS_READ[$i,$j]}} )) && aBENCH_RESULT_ROOTFS_READ_MIN[$i]=${aBENCH_ROOTFS_READ[$i,$j]}
				(( ${aBENCH_ROOTFS_READ[$i,$j]} > ${aBENCH_RESULT_ROOTFS_READ_MAX[$i]:=${aBENCH_ROOTFS_READ[$i,$j]}} )) && aBENCH_RESULT_ROOTFS_READ_MAX[$i]=${aBENCH_ROOTFS_READ[$i,$j]}
				(( aBENCH_RESULT_ROOTFS_READ_AVG[$i] += ${aBENCH_ROOTFS_READ[$i,$j]} ))

				# Last item in current array. Work out averages
				(( $j == ${aBENCH_ROOTFS_INDEX[$i]} - 1 )) || continue
				aBENCH_RESULT_ROOTFS_WRITE_AVG[$i]=$(( ${aBENCH_RESULT_ROOTFS_WRITE_AVG[$i]} / ${aBENCH_ROOTFS_INDEX[$i]} ))
				aBENCH_RESULT_ROOTFS_READ_AVG[$i]=$(( ${aBENCH_RESULT_ROOTFS_READ_AVG[$i]} / ${aBENCH_ROOTFS_INDEX[$i]} ))

			done

		done

		# RAM
		for i in "${!aBENCH_RAM_INDEX[@]}"
		do

			aBENCH_RESULT_RAM_WRITE_MIN[$i]=
			aBENCH_RESULT_RAM_WRITE_MAX[$i]=
			aBENCH_RESULT_RAM_WRITE_AVG[$i]=
			aBENCH_RESULT_RAM_READ_MIN[$i]=
			aBENCH_RESULT_RAM_READ_MAX[$i]=
			aBENCH_RESULT_RAM_READ_AVG[$i]=

			for (( j=0; j<${aBENCH_RAM_INDEX[$i]}; j++ ))
			do

				(( ${aBENCH_RAM_WRITE[$i,$j]} < ${aBENCH_RESULT_RAM_WRITE_MIN[$i]:=${aBENCH_RAM_WRITE[$i,$j]}} )) && aBENCH_RESULT_RAM_WRITE_MIN[$i]=${aBENCH_RAM_WRITE[$i,$j]}
				(( ${aBENCH_RAM_WRITE[$i,$j]} > ${aBENCH_RESULT_RAM_WRITE_MAX[$i]:=${aBENCH_RAM_WRITE[$i,$j]}} )) && aBENCH_RESULT_RAM_WRITE_MAX[$i]=${aBENCH_RAM_WRITE[$i,$j]}
				(( aBENCH_RESULT_RAM_WRITE_AVG[$i] += ${aBENCH_RAM_WRITE[$i,$j]} ))

				(( ${aBENCH_RAM_READ[$i,$j]} < ${aBENCH_RESULT_RAM_READ_MIN[$i]:=${aBENCH_RAM_READ[$i,$j]}} )) && aBENCH_RESULT_RAM_READ_MIN[$i]=${aBENCH_RAM_READ[$i,$j]}
				(( ${aBENCH_RAM_READ[$i,$j]} > ${aBENCH_RESULT_RAM_READ_MAX[$i]:=${aBENCH_RAM_READ[$i,$j]}} )) && aBENCH_RESULT_RAM_READ_MAX[$i]=${aBENCH_RAM_READ[$i,$j]}
				(( aBENCH_RESULT_RAM_READ_AVG[$i] += ${aBENCH_RAM_READ[$i,$j]} ))

				# Last item in current array. Work out averages
				(( $j == ${aBENCH_RAM_INDEX[$i]} - 1 )) || continue
				aBENCH_RESULT_RAM_WRITE_AVG[$i]=$(( ${aBENCH_RESULT_RAM_WRITE_AVG[$i]} / ${aBENCH_RAM_INDEX[$i]} ))
				aBENCH_RESULT_RAM_READ_AVG[$i]=$(( ${aBENCH_RESULT_RAM_READ_AVG[$i]} / ${aBENCH_RAM_INDEX[$i]} ))

			done

		done

		# LAN
		for i in "${!aBENCH_LAN_INDEX[@]}"
		do

			aBENCH_RESULT_NET_LAN_SPEED_MIN[$i]=
			aBENCH_RESULT_NET_LAN_SPEED_MAX[$i]=
			aBENCH_RESULT_NET_LAN_SPEED_AVG[$i]=

			for (( j=0; j<${aBENCH_LAN_INDEX[$i]}; j++ ))
			do

				(( ${aBENCH_NET_LAN_SPEED[$i,$j]} < ${aBENCH_RESULT_NET_LAN_SPEED_MIN[$i]:=${aBENCH_NET_LAN_SPEED[$i,$j]}} )) && aBENCH_RESULT_NET_LAN_SPEED_MIN[$i]=${aBENCH_NET_LAN_SPEED[$i,$j]}
				(( ${aBENCH_NET_LAN_SPEED[$i,$j]} > ${aBENCH_RESULT_NET_LAN_SPEED_MAX[$i]:=${aBENCH_NET_LAN_SPEED[$i,$j]}} )) && aBENCH_RESULT_NET_LAN_SPEED_MAX[$i]=${aBENCH_NET_LAN_SPEED[$i,$j]}
				(( aBENCH_RESULT_NET_LAN_SPEED_AVG[$i] += ${aBENCH_NET_LAN_SPEED[$i,$j]} ))

				# Last item in current array. Work out averages
				(( $j == ${aBENCH_LAN_INDEX[$i]} - 1 )) || continue
				aBENCH_RESULT_NET_LAN_SPEED_AVG[$i]=$(( ${aBENCH_RESULT_NET_LAN_SPEED_AVG[$i]} / ${aBENCH_LAN_INDEX[$i]} ))

			done

		done

		# CustomFS
		for i in "${!aBENCH_CUSTOMFS_INDEX[@]}"
		do

			aBENCH_RESULT_CUSTOMFS_WRITE_MIN[$i]=
			aBENCH_RESULT_CUSTOMFS_WRITE_MAX[$i]=
			aBENCH_RESULT_CUSTOMFS_WRITE_AVG[$i]=
			aBENCH_RESULT_CUSTOMFS_READ_MIN[$i]=
			aBENCH_RESULT_CUSTOMFS_READ_MAX[$i]=
			aBENCH_RESULT_CUSTOMFS_READ_AVG[$i]=

			for (( j=0; j<${aBENCH_CUSTOMFS_INDEX[$i]}; j++ ))
			do

				(( ${aBENCH_CUSTOMFS_WRITE[$i,$j]} < ${aBENCH_RESULT_CUSTOMFS_WRITE_MIN[$i]:=${aBENCH_CUSTOMFS_WRITE[$i,$j]}} )) && aBENCH_RESULT_CUSTOMFS_WRITE_MIN[$i]=${aBENCH_CUSTOMFS_WRITE[$i,$j]}
				(( ${aBENCH_CUSTOMFS_WRITE[$i,$j]} > ${aBENCH_RESULT_CUSTOMFS_WRITE_MAX[$i]:=${aBENCH_CUSTOMFS_WRITE[$i,$j]}} )) && aBENCH_RESULT_CUSTOMFS_WRITE_MAX[$i]=${aBENCH_CUSTOMFS_WRITE[$i,$j]}
				(( aBENCH_RESULT_CUSTOMFS_WRITE_AVG[$i] += ${aBENCH_CUSTOMFS_WRITE[$i,$j]} ))

				(( ${aBENCH_CUSTOMFS_READ[$i,$j]} < ${aBENCH_RESULT_CUSTOMFS_READ_MIN[$i]:=${aBENCH_CUSTOMFS_READ[$i,$j]}} )) && aBENCH_RESULT_CUSTOMFS_READ_MIN[$i]=${aBENCH_CUSTOMFS_READ[$i,$j]}
				(( ${aBENCH_CUSTOMFS_READ[$i,$j]} > ${aBENCH_RESULT_CUSTOMFS_READ_MAX[$i]:=${aBENCH_CUSTOMFS_READ[$i,$j]}} )) && aBENCH_RESULT_CUSTOMFS_READ_MAX[$i]=${aBENCH_CUSTOMFS_READ[$i,$j]}
				(( aBENCH_RESULT_CUSTOMFS_READ_AVG[$i] += ${aBENCH_CUSTOMFS_READ[$i,$j]} ))

				# Last item in current array. Work out averages
				(( $j == ${aBENCH_CUSTOMFS_INDEX[$i]} - 1 )) || continue
				aBENCH_RESULT_CUSTOMFS_WRITE_AVG[$i]=$(( ${aBENCH_RESULT_CUSTOMFS_WRITE_AVG[$i]} / ${aBENCH_CUSTOMFS_INDEX[$i]} ))
				aBENCH_RESULT_CUSTOMFS_READ_AVG[$i]=$(( ${aBENCH_RESULT_CUSTOMFS_READ_AVG[$i]} / ${aBENCH_CUSTOMFS_INDEX[$i]} ))

			done

		done

		# Create HTML file
		cat << _EOF_ > index.html
<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="utf-8">
		<link rel="home" href="https://dietpi.com/">
		<link rel="canonical" href="https://dietpi.com/survey/">
		<title>DietPi-Survey statistics</title>
		<meta name="description" content="DietPi usage statistics and benchmarks based on DietPi-Survey uploads">
		<!-- Twitter meta tags: https://developer.twitter.com/docs/twitter-for-websites/cards -->
		<meta name="twitter:card" content="summary">
		<meta name="twitter:site" content="@DietPi_">
		<meta name="twitter:creator" content="@DietPi_">
		<meta name="twitter:title" content="DietPi-Survey statistics">
		<meta name="twitter:description" content="DietPi usage statistics and benchmarks based on DietPi-Survey uploads">
		<meta name="twitter:image" content="https://dietpi.com/images/dietpi-logo_720x720.png">
		<!-- Open Graph meta tags: https://developers.facebook.com/docs/sharing/webmasters -->
		<meta property="og:locale" content="en_GB">
		<meta property="og:site_name" content="DietPi">
		<meta property="og:type" content="website">
		<meta property="og:url" content="https://dietpi.com/survey/">
		<meta property="og:title" content="DietPi-Survey statistics">
		<meta property="og:description" content="DietPi usage statistics and benchmarks based on DietPi-Survey uploads">
		<meta property="og:image" content="https://dietpi.com/images/dietpi-logo_720x720.png">
		<!-- Adjust width based on screen size -->
		<meta name="viewport" content="width=device-width, initial-scale=1">
		<!-- Favicon and theme: https://realfavicongenerator.net/ -->
		<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png">
		<link rel="icon" type="image/png" sizes="32x32" href="/images/dietpi-logo_32x32.png">
		<link rel="icon" type="image/png" sizes="16x16" href="/images/dietpi-logo_16x16.png">
		<link rel="manifest" href="/site.webmanifest">
		<link rel="mask-icon" href="/images/dietpi-logo_mask_720x720.svg" color="#c5ff00">
		<meta name="msapplication-TileColor" content="#da532c">
		<meta name="theme-color" content="#000000">
		<style>
			html { scroll-behavior: smooth; }
			body {
				color: #ffffff;
				background-color: #181a1c;
				font-family: Arial, sans-serif;
			}
			table { display: block; overflow-x: auto; }
			td { border: 1px solid grey; padding: 5px; }
			a { color: #ffffff; text-decoration: none; }
			a:hover, a:focus, a:active { color: #c5ff00; }
			nav a {
				text-transform: uppercase;
				font-size: 15px;
				line-height: 40px;
				padding: 10px 14px;
				border: 1px solid #181a1c;
				border-radius: 5px;
				transition: border-color 1s;
			}
			nav a:hover,
			nav a:focus,
			nav a:active {
				color: #ffffff;
				border-color: #c5ff00;
			}
			:target:before {
				content: "";
				display: block;
				height: 60px;
				margin-top: -60px;
			}
			a.scrollup {
				position: fixed;
				bottom: 15px;
				right: 15px;
				width: 38px;
				height: 38px;
				text-align: center;
				font-size: 30px;
				font-weight: 900;
				line-height: 42px;
				color: #181a1c;
				background-color: #c5ff00;
				border: 1px solid #181a1c;
				border-radius: 4px;
				transition: color 0.5s, background-color 0.5s, border-color 0.5s;
			}
			a.scrollup:hover,
			a.scrollup:focus,
			a.scrollup:active {
				color: #c5ff00;
				background-color: #181a1c;
				border-color: #c5ff00;
			}
		</style>
	</head>
	<body>
		<nav style="height: 40px; width: 100%; position: fixed; top: 0; left: 0; right: 0; padding: 10px 16px; background-color: #181a1c; display: inline-table">
			<a href="/" rel="home" style="padding: 10px 60px; background-image: url(/images/dietpi-logo_240x80.png); background-size: cover; background-position: bottom"/>
			<a href="#device">Device</a>
			<a href="#distro">Distro</a>
			<a href="#software">Software</a>
			<a href="#benchmark">Benchmark</a>
		</nav>
		<a href="#" class="scrollup">^</a>
		<h2 style="padding-top: 60px">DietPi-Survey statistics</h2>
		<p>Uploads since: 2020-07-01 00:00:00 UTC +0100</p>
		<p>Last update: $(TZ=UTC date '+%Y-%m-%d %T UTC')</p>
		<br>
		<table>
			<tr><td>Total system count</td><td align="right">$SURVEY_COUNT_TOTAL</td></tr>
			<tr><td>Systems sending survey data</td><td align="right">$SURVEY_COUNT_OPTIN</td><td align="right">$(( $SURVEY_COUNT_OPTIN * 100 / $SURVEY_COUNT_TOTAL ))%</td></tr>
			<tr><td>Systems opted out DietPi-Survey</td><td align="right">$SURVEY_COUNT_EMPTY</td><td align="right">$(( $SURVEY_COUNT_EMPTY * 100 / $SURVEY_COUNT_TOTAL ))%</td></tr>
		</table>

		<h3 id="version"><a href="#version">DietPi versions &para</a></h3>
		<table>
			$(for i in "${!aDIETPI_VERSION[@]}"; do echo "<tr><td>DietPi v$i</td><td align=\"right\">	${aDIETPI_VERSION[$i]}</td><td align=\"right\">$(( ${aDIETPI_VERSION[$i]} * 100 / $SURVEY_COUNT_OPTIN ))%</td></tr>"; done | sort -nrk 1.17,1.20 -t '	')
		</table>

		<h3 id="git"><a href="#git">Git branches &para</a></h3>
		<table>
			$(for i in "${!aGIT_BRANCH[@]}"; do echo "<tr><td>$i</td><td align=\"right\">	${aGIT_BRANCH[$i]}</td><td align=\"right\">$(( ${aGIT_BRANCH[$i]} * 100 / $SURVEY_COUNT_OPTIN ))%</td></tr>"; done | sort -nrk 2 -t '	')
		</table>

		<h3 id="device"><a href="#device">Devices &para</a></h3>
		<table>
			$(for i in "${!aDEVICE_NAME[@]}"; do echo "<tr><td>$i</td><td align=\"right\">	${aDEVICE_NAME[$i]}</td><td align=\"right\">$(( ${aDEVICE_NAME[$i]} * 100 / $SURVEY_COUNT_OPTIN ))%</td></tr>"; done | sort -nrk 2 -t '	')
		</table>

		<h3 id="arch"><a href="#arch">CPU architectures &para</a></h3>
		<table>
			$(for i in "${!aCPU_ARCH[@]}"; do echo "<tr><td>$i</td><td align=\"right\">	${aCPU_ARCH[$i]}</td><td align=\"right\">$(( ${aCPU_ARCH[$i]} * 100 / $SURVEY_COUNT_OPTIN ))%</td></tr>"; done | sort -nrk 2 -t '	')
		</table>

		<h3 id="cores"><a href="#cores">CPU core counts &para</a></h3>
		<table>
			$(for i in "${!aCPU_COUNT[@]}"; do echo "<tr><td>$i Core(s)</td><td align=\"right\">	${aCPU_COUNT[$i]}</td><td align=\"right\">$(( ${aCPU_COUNT[$i]} * 100 / $SURVEY_COUNT_OPTIN ))%</td></tr>"; done | sort -nrk 2 -t '	')
		</table>

		<h3 id="distro"><a href="#distro">Distro versions &para</a></h3>
		<table>
			$(for i in "${!aDISTRO_VERSION[@]}"; do echo "<tr><td>$i</td><td align=\"right\">	${aDISTRO_VERSION[$i]}</td><td align=\"right\">$(( ${aDISTRO_VERSION[$i]} * 100 / $SURVEY_COUNT_OPTIN ))%</td></tr>"; done | sort -nrk 2 -t '	')
		</table>

		<h3 id="raspbian"><a href="#raspbian">RPi Debian 64-bit vs Raspbian 32-bit &para</a></h3>
		<table>
			<tr><td>Debian (64-bit) is used by</td><td align="right">${aRASPBIAN[0]} of $(( ${aRASPBIAN[0]} + ${aRASPBIAN[1]} )) RPi systems</td><td align=\"right\">$(( ${aRASPBIAN[0]} * 100 / ( ${aRASPBIAN[0]} + ${aRASPBIAN[1]} ) ))%</td></tr>
		</table>

		<h3 id="autostart"><a href="#autostart">Autostart options &para</a></h3>
		<table>
			$(for i in "${!aAUTOSTART_OPTION[@]}"; do echo "<tr><td>$i</td><td align=\"right\">	${aAUTOSTART_OPTION[$i]}</td><td align=\"right\">$(( ${aAUTOSTART_OPTION[$i]} * 100 / $SURVEY_COUNT_OPTIN ))%</td></tr>"; done | sort -nrk 2 -t '	')
		</table>

		<h3 id="automation"><a href="#automation">DietPi-Automation &para</a></h3>
		<table>
			<tr><td>Used by</td><td align="right">${aAUTO_SETUP_AUTOMATED[1]} of $SURVEY_COUNT_OPTIN systems</td><td align=\"right\">$(( ${aAUTO_SETUP_AUTOMATED[1]} * 100 / $SURVEY_COUNT_OPTIN ))%</td></tr>
		</table>

		<h3 id="network"><a href="#network">Network interfaces &para</a></h3>
		<table>
			$(for i in "${!aNETWORK_INTERFACE[@]}"; do echo "<tr><td>$i</td><td align=\"right\">	${aNETWORK_INTERFACE[$i]}</td><td align=\"right\">$(( ${aNETWORK_INTERFACE[$i]} * 100 / $SURVEY_COUNT_OPTIN ))%</td></tr>"; done | sort -nrk 2 -t '	')
		</table>

		<h3 id="software"><a href="#software">Installed software titles &para</a></h3>
		<table>
			$(for i in "${!aSOFTWARE[@]}"; do echo "<tr><td>$i</td><td align=\"right\">	${aSOFTWARE[$i]}</td><td align=\"right\">$(( ${aSOFTWARE[$i]} * 100 / $SURVEY_COUNT_OPTIN ))%</td></tr>"; done | sort -nrk 2 -t '	')
		</table>

		<h3 id="benchmark"><a href="#benchmark">DietPi-Benchmarks | CPU &para</a></h3>
		<table>
			<tr>
				<td colspan="2"/>
				<td colspan="3" bgcolor="#5B5B5B">CPU time (seconds, lower is faster)</td>
				<td colspan="3" bgcolor="#5B5B5B">CPU idle temp [&#176;C]</td>
				<td colspan="3" bgcolor="#5B5B5B">CPU load temp [&#176;C]</td>
			</tr>
			<tr>
				<td bgcolor="#5B5B5B">Device</td>
				<td bgcolor="#5B5B5B">Count</td>
				<td bgcolor="#34005D">Average</td>
				<td bgcolor="#2B5D00">Fastest</td>
				<td bgcolor="#5D0000">Slowest</td>
				<td bgcolor="#34005D">Average</td>
				<td bgcolor="#2B5D00">Lowest</td>
				<td bgcolor="#5D0000">Highest</td>
				<td bgcolor="#34005D">Average</td>
				<td bgcolor="#2B5D00">Lowest</td>
				<td bgcolor="#5D0000">Highest</td>
			</tr>
			$(for i in "${!aBENCH_CPU_INDEX[@]}"; do echo "<tr><td>${aHW_NAME[$i]:=$i}</td><td>${aBENCH_CPU_INDEX[$i]}</td><td bgcolor=\"#34005D\">	${aBENCH_RESULT_CPU_AVG[$i]}</td><td bgcolor=\"#2B5D00\">${aBENCH_RESULT_CPU_MIN[$i]}</td><td bgcolor=\"#5D0000\">${aBENCH_RESULT_CPU_MAX[$i]}</td><td bgcolor=\"#34005D\">${aBENCH_RESULT_CPU_TEMP_START_AVG[$i]}</td><td bgcolor=\"#2B5D00\">${aBENCH_RESULT_CPU_TEMP_START_MIN[$i]}</td><td bgcolor=\"#5D0000\">${aBENCH_RESULT_CPU_TEMP_START_MAX[$i]}</td><td bgcolor=\"#34005D\">${aBENCH_RESULT_CPU_TEMP_END_AVG[$i]}</td><td bgcolor=\"#2B5D00\">${aBENCH_RESULT_CPU_TEMP_END_MIN[$i]}</td><td bgcolor=\"#5D0000\">${aBENCH_RESULT_CPU_TEMP_END_MAX[$i]}</td></tr>"; done | sort -nk 2 -t '	')
		</table>

		<h3 id="bench_ram"><a href="#bench_ram">DietPi-Benchmarks | RAM I/O &para</a></h3>
		<table>
			<tr>
				<td colspan="2"/>
				<td colspan="3" bgcolor="#5B5B5B">RAM write [MiB/s]</td>
				<td colspan="3" bgcolor="#5B5B5B">RAM read [MiB/s]</td>
			</tr>
			<tr>
				<td bgcolor="#5B5B5B">Device</td>
				<td bgcolor="#5B5B5B">Count</td>
				<td bgcolor="#34005D">Average</td>
				<td bgcolor="#2B5D00">Fastest</td>
				<td bgcolor="#5D0000">Slowest</td>
				<td bgcolor="#34005D">Average</td>
				<td bgcolor="#2B5D00">Fastest</td>
				<td bgcolor="#5D0000">Slowest</td>
			</tr>
			$(for i in "${!aBENCH_RAM_INDEX[@]}"; do echo "<tr><td>${aHW_NAME[$i]:=$i}</td><td>${aBENCH_RAM_INDEX[$i]}</td><td bgcolor=\"#34005D\">	${aBENCH_RESULT_RAM_WRITE_AVG[$i]}</td><td bgcolor=\"#2B5D00\">${aBENCH_RESULT_RAM_WRITE_MAX[$i]}</td><td bgcolor=\"#5D0000\">${aBENCH_RESULT_RAM_WRITE_MIN[$i]}</td><td bgcolor=\"#34005D\">${aBENCH_RESULT_RAM_READ_AVG[$i]}</td><td bgcolor=\"#2B5D00\">${aBENCH_RESULT_RAM_READ_MAX[$i]}</td><td bgcolor=\"#5D0000\">${aBENCH_RESULT_RAM_READ_MIN[$i]}</td></tr>"; done | sort -nrk 2 -t '	')
		</table>

		<h3 id="bench_disk"><a href="#bench_disk">DietPi-Benchmarks | RootFS I/O &para</a></h3>
		<table>
			<tr>
				<td colspan="2"/>
				<td colspan="3" bgcolor="#5B5B5B">RootFS write [MiB/s]</td>
				<td colspan="3" bgcolor="#5B5B5B">RootFS read [MiB/s]</td>
			</tr>
			<tr>
				<td bgcolor="#5B5B5B">Device</td>
				<td bgcolor="#5B5B5B">Count</td>
				<td bgcolor="#34005D">Average</td>
				<td bgcolor="#2B5D00">Fastest</td>
				<td bgcolor="#5D0000">Slowest</td>
				<td bgcolor="#34005D">Average</td>
				<td bgcolor="#2B5D00">Fastest</td>
				<td bgcolor="#5D0000">Slowest</td>
			</tr>
			$(for i in "${!aBENCH_ROOTFS_INDEX[@]}"; do echo "<tr><td>${aHW_NAME[$i]:=$i}</td><td>${aBENCH_ROOTFS_INDEX[$i]}</td><td bgcolor=\"#34005D\">	${aBENCH_RESULT_ROOTFS_WRITE_AVG[$i]}</td><td bgcolor=\"#2B5D00\">${aBENCH_RESULT_ROOTFS_WRITE_MAX[$i]}</td><td bgcolor=\"#5D0000\">${aBENCH_RESULT_ROOTFS_WRITE_MIN[$i]}</td><td bgcolor=\"#34005D\">${aBENCH_RESULT_ROOTFS_READ_AVG[$i]}</td><td bgcolor=\"#2B5D00\">${aBENCH_RESULT_ROOTFS_READ_MAX[$i]}</td><td bgcolor=\"#5D0000\">${aBENCH_RESULT_ROOTFS_READ_MIN[$i]}</td></tr>"; done | sort -nrk 2 -t '	')
		</table>

		<h3 id="bench_custom"><a href="#bench_custom">DietPi-Benchmarks | Custom FS I/O &para</a></h3>
		<table>
			<tr>
				<td colspan="2"/>
				<td colspan="3" bgcolor="#5B5B5B">Custom FS write [MiB/s]</td>
				<td colspan="3" bgcolor="#5B5B5B">Custom FS read [MiB/s]</td>
			</tr>
			<tr>
				<td bgcolor="#5B5B5B">Device</td>
				<td bgcolor="#5B5B5B">Count</td>
				<td bgcolor="#34005D">Average</td>
				<td bgcolor="#2B5D00">Fastest</td>
				<td bgcolor="#5D0000">Slowest</td>
				<td bgcolor="#34005D">Average</td>
				<td bgcolor="#2B5D00">Fastest</td>
				<td bgcolor="#5D0000">Slowest</td>
			</tr>
			$(for i in "${!aBENCH_CUSTOMFS_INDEX[@]}"; do echo "<tr><td>${aHW_NAME[$i]:=$i}</td><td>${aBENCH_CUSTOMFS_INDEX[$i]}</td><td bgcolor=\"#34005D\">	${aBENCH_RESULT_CUSTOMFS_WRITE_AVG[$i]}</td><td bgcolor=\"#2B5D00\">${aBENCH_RESULT_CUSTOMFS_WRITE_MAX[$i]}</td><td bgcolor=\"#5D0000\">${aBENCH_RESULT_CUSTOMFS_WRITE_MIN[$i]}</td><td bgcolor=\"#34005D\">${aBENCH_RESULT_CUSTOMFS_READ_AVG[$i]}</td><td bgcolor=\"#2B5D00\">${aBENCH_RESULT_CUSTOMFS_READ_MAX[$i]}</td><td bgcolor=\"#5D0000\">${aBENCH_RESULT_CUSTOMFS_READ_MIN[$i]}</td></tr>"; done | sort -nrk 2 -t '	')
		</table>

		<h3 id="bench_lan"><a href="#bench_lan">DietPi-Benchmarks | LAN I/O &para</a></h3>
		<table>
			<tr>
				<td colspan="2"/>
				<td colspan="3" bgcolor="#5B5B5B">Transfer rate [MiB/s]</td>
			</tr>
			<tr>
				<td bgcolor="#5B5B5B">Device</td>
				<td bgcolor="#5B5B5B">Count</td>
				<td bgcolor="#34005D">Average</td>
				<td bgcolor="#2B5D00">Fastest</td>
				<td bgcolor="#5D0000">Slowest</td>
			</tr>
			$(for i in "${!aBENCH_LAN_INDEX[@]}"; do echo "<tr><td>${aHW_NAME[$i]:=$i}</td><td>${aBENCH_LAN_INDEX[$i]}</td><td bgcolor=\"#34005D\">	${aBENCH_RESULT_NET_LAN_SPEED_AVG[$i]}</td><td bgcolor=\"#2B5D00\">${aBENCH_RESULT_NET_LAN_SPEED_MAX[$i]}</td><td bgcolor=\"#5D0000\">${aBENCH_RESULT_NET_LAN_SPEED_MIN[$i]}</td></tr>"; done | sort -nrk 2 -t '	')
		</table>
	</body>
</html>
_EOF_

		# Move HTML page in place
		if [[ $G_DEBUG == 1 ]]; then

			mv index.html /var/www/survey/debug.html

		else

			mv index.html /var/www/survey/index.html

		fi

	}

	#-----------------------------------------------------------
	# Main
	#-----------------------------------------------------------
	Main
	#-----------------------------------------------------------
	exit 0
	#-----------------------------------------------------------

} &>> /var/log/dietpi-survey_report.log
